package cheme.ProcessEditor.Figures;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.Border;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.swt.graphics.Color;

import cheme.ProcessEditor.ChemePresentation;
import cheme.ProcessEditor.Figures.Util.EditableLabel;

public class FieldFig extends EditableLabel implements IFigure
{
	List<IFigure> externalChildren = new ArrayList<IFigure>();
	private Insets insets;
	private boolean truncationDisabled = true;
	
	public FieldFig(String text)
	{
		super(text);
		initPresentation();
	}
	
	protected void initPresentation()
	{
		setOpaque(true);
		setPresentation(
				ChemePresentation.Fields.defaultBackground,
				ChemePresentation.Fields.defaultForeground,
				ChemePresentation.Fields.defaultBorder
		);
	}
	
	public void setPresentation(Color Background, Color foreground, Border border)
	{
		setBackgroundColor(Background);
		setForegroundColor(foreground);
		setBorder(border);
	}
	
	@Override
	public Insets getInsets()
	{
		return new Insets(2,6,3,6);
	}
	
	public void setInsets(Insets insets)
	{
		this.insets = insets;
	}

	/**
	 * Calculates the amount of the Label's current text will fit in the Label, including an 
	 * elipsis "..." if truncation is required. 
	 * 
	 * @return the substring
	 * 
	 * JB: I override this to prohibit truncation by always returning the full
	 * size of the text. If truncation is not disabled, defer the decision to 
	 * the base class.
	 */
	public String getSubStringText()
	{
		if(truncationDisabled)
		{
			return getText();
		}
		
		return super.getSubStringText();
	}

	/**
	 * @return the DisabledTruncation
	 */
	public boolean tuncationDisabled()
	{
		return truncationDisabled;
	}

	/**
	 * @param DisabledTruncation the truncationDisabled to set
	 */
	public void DisabledTruncation(boolean truncationDisabled)
	{
		this.truncationDisabled = truncationDisabled;
	}
	
//	public List<IFigure> getExternalChildren()
//	{
//		return externalChildren;
//	}
//	
//	public void addExternalChild(IFigure child)
//	{
//		getExternalChildren().add(child);
//	}
//	
//	public void removeExternalChild(IFigure child)
//	{
//		getExternalChildren().remove(child);
//	}
}
